package com.example.lxd.broadcast2;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    private IntentFilter intentFilter;

    private BroadcastReceiver2 broadcastReceiver2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        intentFilter = new IntentFilter();
        intentFilter.addAction("com.example.lxd.My_Broadcast");
        broadcastReceiver2 = new BroadcastReceiver2();
        intentFilter.setPriority(100);
        registerReceiver(broadcastReceiver2, intentFilter);
    }

    class BroadcastReceiver2 extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            Log.d(TAG, "onReceive: receive broadcast2");
            Bundle bundle = new Bundle();
            bundle.putString("first", " i am broadcast2 存入的消息");
            setResultExtras(bundle); // 给下一个接收器传递消息
//            abortBroadcast(); 取消继续传播
        }
    }
}
